<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Hoodoo::Client::PaginatedEnumeration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        <h1>
            <span class="type">Module</span>
            Hoodoo::Client::PaginatedEnumeration
        </h1>
        <ul class="files">
            <li><a href="../../../files/lib/hoodoo/client/paginated_enumeration_rb.html">lib/hoodoo/client/paginated_enumeration.rb</a></li>
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
    <div class="description">
      
<p>Ruby mixin providing an enumeration mechanism, allowing the caller to
iterate over all the resource instances in the list, automatically
performing the necessary pagination behind the scenes.</p>

    </div>








    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
        <dt>E</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-enumerate_all">enumerate_all</a>
              </li>
          </ul>
        </dd>
    </dl>








      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
          <tr valign='top' id='attribute-i-next_page_proc'>
            <td class='attr-rw'>
              [RW]
            </td>
            <td class='attr-name'>next_page_proc</td>
            <td class='attr-desc'><p>Proc called by <a
href="PaginatedEnumeration.html#method-i-enumerate_all">#enumerate_all</a>
to provide the next &#39;page&#39; of values to be enumerated through.
Returns an <a
href="AugmentedArray.html">Hoodoo::Client::AugmentedArray</a>.</p></td>
          </tr>
      </table>


    <!-- Methods -->
      <div class="sectiontitle">Instance Public methods</div>
        <div class="method">
          <div class="title method-title" id="method-i-enumerate_all">
              <b>enumerate_all</b>()
            <a href="../../../classes/Hoodoo/Client/PaginatedEnumeration.html#method-i-enumerate_all" name="method-i-enumerate_all" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Yields each resource instance, automatically paginating through the entire
set of resources.</p>

<p>Provide a block to process each resource instance. For example:</p>

<pre><code>results = members.list(:search =&gt; { :surname =&gt; &#39;Smith&#39; } ).enumerate_all do | member |
  if member.platform_errors.has_errors?
    .. deal with error ...
    break
  else
    .. process member ...
  end
end</code></pre>

<p>Each iteration yields a <a
href="AugmentedHash.html">Hoodoo::Client::AugmentedHash</a> representation
of the requested resource instance. The caller must check for errors on the
value yielded with each iteration, as per the example above.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-enumerate_all_source')" id="l_method-i-enumerate_all_source">show</a>
              </p>
              <div id="method-i-enumerate_all_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/client/paginated_enumeration.rb, line 43</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">enumerate_all</span>

  <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;Must provide a block to enumerate_all&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>

  <span class="ruby-comment"># The first set of results is in &#39;this&#39; AugmentedArray</span>
  <span class="ruby-identifier">results</span> = <span class="ruby-keyword">self</span>

  <span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span>

    <span class="ruby-keyword">if</span> <span class="ruby-identifier">results</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-number">0</span>

      <span class="ruby-keyword">if</span> <span class="ruby-identifier">results</span>.<span class="ruby-identifier">platform_errors</span>.<span class="ruby-identifier">has_errors?</span>
        <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Hoodoo::Client:: PaginatedEnumeration#enumerate_all: Unexpected internal state combination of results set and results error indication&quot;</span>
      <span class="ruby-keyword">end</span>

      <span class="ruby-comment"># Yield a resource at a time to the caller</span>
      <span class="ruby-comment">#</span>
      <span class="ruby-comment"># Note: An inter-resource call in a single service returns each</span>
      <span class="ruby-comment">#       resource as a Hash, which must be converted to AugmentedHash</span>
      <span class="ruby-identifier">results</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">result</span> <span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">to_augmented_hash</span>(<span class="ruby-identifier">result</span>)
      <span class="ruby-keyword">end</span>
      <span class="ruby-identifier">results</span> = <span class="ruby-identifier">next_page_proc</span>.<span class="ruby-identifier">call</span>()
    <span class="ruby-keyword">else</span>
      <span class="ruby-comment"># Return errors in an (empty) AugmentedHash</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">results</span>.<span class="ruby-identifier">platform_errors</span>.<span class="ruby-identifier">has_errors?</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">copy_hash_errors_and_options</span>( <span class="ruby-constant">Hoodoo</span><span class="ruby-operator">::</span><span class="ruby-constant">Client</span><span class="ruby-operator">::</span><span class="ruby-constant">AugmentedHash</span>.<span class="ruby-identifier">new</span>, <span class="ruby-identifier">results</span> )
      <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">break</span>
    <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">end</span>

<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
</div>

    </div>
  </body>
</html>
